﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;


namespace IHISCETeim.DAL
{
    public   class FTradeWarehouseFeeDAL
    {
        public static int Add(FTradeWarehouseFeeInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeWarehouseFee_Add");
            DB.AddInParameter(dbCommand, "XingHao", DbType.String, obj.XingHao);
            DB.AddInParameter(dbCommand, "JiHao", DbType.String, obj.JiHao);
            DB.AddInParameter(dbCommand, "JingXiaoShang", DbType.String, obj.JingXiaoShang);
            DB.AddInParameter(dbCommand, "JinE", DbType.Decimal, obj.JinE);
            DB.AddInParameter(dbCommand, "SetDate", DbType.DateTime, obj.SetDate);
            DB.AddInParameter(dbCommand, "Remark", DbType.String, obj.Remark);
            DB.AddInParameter(dbCommand, "AddRealName", DbType.String, obj.AddRealName);
            //return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static bool Delete(int ID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeWarehouseFee_Delete", ID);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static IDataReader GetList(int ID)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeWarehouseFee_GetList", ID);
            return DB.ExecuteReader(dbCommand);
        }
        public static DataTable GetPagination(string whereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeWarehouseFee_GetPagination");
            DB.AddInParameter(dbCommand, "whereSql", DbType.String, whereSql);
            DB.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            DB.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            DB.AddInParameter(dbCommand, "Sort", DbType.String, Sort);
            DB.AddOutParameter(dbCommand, "TotalCount", DbType.Int32, 8);
            DataTable dt = DB.ExecuteDataSet(dbCommand).Tables[0];

            TotalCount = Convert.ToInt32(DB.GetParameterValue(dbCommand, "TotalCount"));
            return dt;
        }
        public static bool Update(FTradeWarehouseFeeInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeWarehouseFee_Update");
            DB.AddInParameter(dbCommand, "ID", DbType.Int32, obj.ID);
            DB.AddInParameter(dbCommand, "XingHao", DbType.String, obj.XingHao);
            DB.AddInParameter(dbCommand, "JiHao", DbType.String, obj.JiHao);
            DB.AddInParameter(dbCommand, "JingXiaoShang", DbType.String, obj.JingXiaoShang);
            DB.AddInParameter(dbCommand, "JinE", DbType.Decimal, obj.JinE);
            DB.AddInParameter(dbCommand, "SetDate", DbType.DateTime, obj.SetDate);
            DB.AddInParameter(dbCommand, "Remark", DbType.String, obj.Remark);

            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch (Exception exc)
            {
                return false;
            }
        }
        /// <summary>
        /// 定时执行同步,如果应收帐款有相应的记录，则把相应入库检查费添加到维保费，同时更新实现销售时间
        /// </summary>
        /// <returns></returns>
        public static bool ExecSync()
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FTradeWarehouseFee_ExecSync");
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
